
local S = mobs.intllib

local guard_types = {

	{	nodes = {"ethereal:dry_dirt", "ethereal:dirt_with_dry_grass"},
		skins = {"mobs_sand_guard.png", "mobs_sand_guard2.png"},
		drops = {
			{name = "mobs:leather", chance = 1, min = 7, max = 11},
			{name = "ethereal:dirt_with_dry_grass", chance = 1, min = 10, max = 17},
			{name = "default:diamond", chance = 1, min = 9, max = 22},
		},
	sand_guard = true
	},
}



-- Dungeon Guard

mobs:register_mob("mobs_monster:dungeon_guard", {
	type = "monster",
	passive = false,
	attack_type = "dogfight",
	pathfinding = true,
	reach = 2,
	damage = 7,
	hp_min = 200,
	hp_max = 300,
	armor = 30,
	collisionbox = {-0.8, -1, -0.8, 0.8, 1.6, 0.8},
	visual_size = {x=1, y=1},
	visual = "mesh",
	mesh = "mobs_dungeon_master.b3d",
	textures = {
		{"mobs_dungeon_guard.png"},
		{"mobs_dungeon_guard2.png"},
		{"mobs_dungeon_guard3.png"},
	},
	makes_footstep_sound = true,
	sounds = {
		random = "mobs_dungeonmaster",
	},
	walk_velocity = 1,
	run_velocity = 3,
	knock_back = false,
	pathfinding = true,
	jump = true,
	jump_height = 2.0,
	stepheight = 1.1,
	fear_height = 5,
	floats = 0,
	view_range = 40,
	drops = {
		{name = "default:mese_crystal_fragment", chance = 1, min = 9, max = 26},
		{name = "default:mese_crystal_fragment", chance = 1, min = 9, max = 26},
		{name = "mobs:leather", chance = 1, min = 6, max = 9},
		{name = "default:mese_crystal", chance = 1, min = 5, max = 9},
		{name = "default:diamond", chance = 1, min = 4, max = 7},
		{name = "default:diamondblock", chance = 1, min = 1, max = 1},
	},
	water_damage = 0,
	lava_damage = 20,
	light_damage = 0,
	fear_height = 7,
	animation = {
		stand_start = 0,
		stand_end = 19,
		walk_start = 20,
		walk_end = 35,
		punch_start = 36,
		punch_end = 48,
		speed_normal = 15,
		speed_run = 20,
	},
	
	replace_rate = 1,
	replace_what = {"default:stone_with_iron", "default:stone_with_copper", "default:stone_with_tin", "default:stone_with_coal",
	"default:stone_with_diamond", "default:stone_with_mese", "moreores:mineral_silver", "moreores:mineral_mithril"},
	replace_with = "default:stone",
	replace_offset = -2,
	
	
	on_spawn = function(self)

		local pos = self.object:get_pos() ; pos.y = pos.y - 1
		local tmp

		for n = 1, #guard_types do

			tmp = guard_types[n]

			if minetest.find_node_near(pos, 1, tmp.nodes) then
				
				self.base_texture = { tmp.skins[math.random(#tmp.skins)] }
				self.object:set_properties({textures = self.base_texture})

				if tmp.drops then
					self.drops = tmp.drops
				end
				
				if tmp.sand_guard then
					self.hp_min = 100
					self.hp_max = 150
					self.armor = 65
					self.replace_rate = 0
				end
					

				return true
			end
		end

		return true -- run only once, false/nil runs every activation
	end,
})


if not mobs.custom_spawn_monster then
mobs:spawn({
	name = "mobs_monster:dungeon_guard",
	nodes = {"default:stone_with_mese", "ethereal:dry_dirt", "ethereal:dirt_with_dry_grass"},
	max_light = 2,
	chance = 7000,
	max_height = 30,
	active_object_count = 3,
})
end


mobs:register_egg("mobs_monster:dungeon_guard", S("Dungeon Guard"), "fire_basic_flame.png", 1)


mobs:alias_mob("mobs:dungeon_guard", "mobs_monster:dungeon_guard")
